home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / vbtips.zip / VB-TIPS.TXT
Text File  |  1991-08-04  |  33KB  |  1,078 lines

  1.                                    VB Tips
  2.  
  3.                       Compiled by Nelson Ford, 71355,470
  4.                   For distribution on the MSLANG Forum only.
  5.  
  6. This is a compilation of information about VB that has flowed through the
  7. Forum here (plus my own input). The hope is that new users can refer to this
  8. file rather than having to ask the same questions on the forum all the time.
  9. Experienced users whose memory is bad as mine might benefit from this as well.
  10.  
  11. Main contributors are:
  12. Jonathan Zuck
  13. Keith Funk
  14. Mark Novisoff
  15. Ted Young
  16. Dennis Harrington
  17. the Microsoft Section Leaders
  18.  
  19. Note: There are a number of very valuable free DLL's and VB routines on DL1
  20. ("New Uploads") and DL6 ("VB"). It is highly recommended that you Browse these
  21. two DL's. A few are mentioned in this file, but many more are available.
  22.  
  23. Uploading: If you would like to share your coding with others, upload to DL1,
  24. not DL6. All new uploads go to DL1 for 30 days and then are moved to the
  25. appropriate DL (6, for VB). Do NOT put VBRUN100.DLL in your archive, nor any
  26. of the other DLLs that are available on here. All that does is increase the
  27. download time for everyone who already has those files. Instead, in your
  28. upload description, just tell people that they need to download those files
  29. too, if they don't already have them.
  30.  
  31.  
  32. CONTENTS:  [Names in brackets are files in the MSLANG DL's 1 or 6.]
  33.  
  34. General:
  35.   Button Colors
  36.   .EXE Size
  37.   Far Pointers
  38.   Help Files
  39.   Icon - Get Rid Of
  40.   Networks & VB
  41.   Saving Your Work
  42.   Screen type
  43.   Sound.DLL (Need TPW)
  44.   Type...End Type
  45.  
  46. Arrays:
  47.   Dynamic Arrays
  48.   [VBSORT]
  49.  
  50. Combo Boxes:
  51.   Changing Text
  52.   Color
  53.   Pseudo Combo Dropdown List Box
  54.  
  55. DOS Functions:
  56.   File Copying
  57.   [VBDOS]
  58.  
  59. Form & Control Placement, Sizing:
  60.   Controlling Form Size
  61.   "Floating" Window
  62.   Form Size and Granularity
  63.   Grouped Controls
  64.   Mouse Pointer, Position
  65.   Placing Forms, Controls
  66.  
  67. File I/O:
  68.   Btrieve
  69.   Deleting Data in Sequential File
  70.   MKI$ & CVI in VB
  71.  
  72. Fonts:
  73.   Using Different Fonts, Colors in a Box
  74.   System Font
  75.  
  76. Forms: (Also see "Form & Control Placement, Sizing", above)
  77.   Focus & Order of Execution
  78.     Focus on StartUp
  79.   SetFocus
  80.  
  81. Keyboard & Mouse:
  82.   Trapping Double-Click before Click
  83.   Using "Enter" in Place of "Tab"
  84.  
  85. List Boxes:
  86.   Finding an Item Added to a Sorted List Box
  87.   Inhibiting Screen Updating
  88.   Linking Sorted and Unsorted List Boxes
  89.   Searching For An Item
  90.   [VBSORT]
  91.  
  92. Picture Boxes:
  93.   Copying a Drawing to Clipboard
  94.   Drawing - Scale
  95.   Saving Picture Files
  96.  
  97. Printer:
  98.   Printer Setup
  99.   Printer Control Codes
  100.   Printing Forms
  101.  
  102. System:
  103.   Calling the Windows 3 Calculator
  104.   hWnd for a Control
  105.   .INI Files
  106.   Multi-Instance App Prevention
  107.   SendMessage
  108.   Windows Termination
  109.  
  110. Text Boxes:
  111.   Cursor (text), Position
  112.   Data Entry Masking
  113.   Data Entry Routine
  114.   Data Entry Text Limit
  115.   Flicker
  116.   Flashing Text
  117.  
  118. Timer
  119.   Using the Timer
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126. Button Colors:
  127.  
  128. Button colors are controlled by WIN.INI.  See the 6/11/91 issue of PC Mag
  129. for details. Of course, changes you make there apply globally.
  130. ---------------
  131.  
  132.  
  133. .EXE Size:
  134.  
  135. 1. Long variable names increase EXE size.
  136. 2. Comments add a couple of bytes per line to EXE size.
  137. 3. A Global DIM of an array adds to EXE size.
  138.    For example:
  139.      Global sample as string*20000
  140.    will add about 20k to the size of the EXE file, but the same DIM
  141.    in a Form will not.
  142. ---------------
  143.  
  144.  
  145.  
  146. Far Pointers:
  147.  
  148. Here's a question regarding direct calls to the Windows API from a Visual Basic
  149. procedure. In trying to set up a call to the API entry "Polygon", I discovered
  150. that one of the arguments is a far pointer to an array of structures. I've
  151. searched the VB documentation, but can't find a method that will return the
  152. run-time address of a variable (or an array element) as a far pointer.
  153.  
  154. Is there a VB technique for passing a far pointer as an argument -- if so, how?
  155. Also, how would such an argument be specified in the corresponding DECLARE
  156. statement? Many thanks to anyone who can supply this information.
  157.  
  158. (Fm: Mark Novisoff (TA) 73047,3706)
  159.  
  160. If the structures themselves don't require pointers (which is the case with
  161. Polygon), then it's a piece of cake. Use TYPE...END TYPE to declare a model
  162. structure, and then DIM an array of the structures.
  163.  
  164. In your Global module Declare statement, use the "As" syntax:
  165.  
  166.    Type Points
  167.      ' Define the structure
  168.      X As Integer
  169.      Y As Integer
  170.    End Type
  171.    Declare Function Polygon Lib "Gdi" (hDC%, MyStruc As Points, nCount%)
  172.  
  173. In your code:
  174.  
  175.    ReDim MyStrucArray(0 To 10) As Points
  176.    ' Set the variables in the array here
  177.    Result = Polygon(hDC%, MyStrucArray(0), nCount%)
  178.  
  179. Note that this results in passing a far pointer to the zeroth element of the
  180. array. Because the length of the structure is known to the DLL routine, it
  181. will figure out where the rest of the elements are.
  182. ---------------
  183.  
  184.  
  185. Help Files:
  186.  
  187. 1. You can create Help files more easily and cheaply than with the SDK: use
  188.    the help compiler (HC.EXE) that comes with Turbo Pascal for Windows and
  189.    Borland C++.
  190.  
  191. 2. A shareware program named Xantippe is a good front-end for making help
  192.    files.
  193. ---------------
  194.  
  195.  
  196. Icon - Get Rid Of:
  197.  
  198. 1. Click on the form
  199. 2. Select the Icon property from the properties bar.
  200. 3. Click on the middle portion of the properties bar, where (icon) shows.
  201. 4. Press the Del key
  202. ---------------
  203.  
  204.  
  205. Networks & VB:
  206.  
  207. VBRUN100.DLL and VB apps (EXE's) should be placed on each machine's hard disk
  208. to avoid significant performance degradation.
  209. ---------------
  210.  
  211.  
  212. Saving Your Work:
  213.  
  214. Several users have reported losing their work in different ways. If you always
  215. save before test-running your code, you can prevent most losses. If you get
  216. any kind of warnings or other indications that something might be wrong with
  217. your system, try to get into DOS (or use File Manager) and copy your project
  218. files to a backup directory. Many people have had their project files
  219. "trashed" when the system went screwy. There is a utility on the DLs here for
  220. copying all the files in a Project - very handy to have, although a better
  221. idea, generally, is to keep each project in its own subdirectory.
  222. ---------------
  223.  
  224.  
  225. Screen type:
  226.  
  227. z = Screen.Height
  228. If z = 6000 Then
  229.   Type$="CGA"
  230. ElseIf z = 7000 Then
  231.   Type$ = "EGA"
  232. ElseIf z > 7000 Then
  233.   Type$ = "VGA or Better"
  234. End if
  235.  
  236. There's another way to do this, calling GetDeviceCaps to find out the vertical
  237. resolution; but this method is a lot easier... BTW, if you want to know if it
  238. is exactly VGA, not "or better" (i.e., better than 640x480), the number for
  239. that 7200 if memory serves...
  240. ---------------
  241.  
  242.  
  243. Sound.DLL (Need TPW):
  244.  
  245. Here's my DLL written in TPW. I had no documentation besides the Windows
  246. Programmer's Reference so maybe someone here can tell me if I'm on the right
  247. track. Some questions come to mind such as: how large shoule I make the voice
  248. queue? Is it unecessary to open and close the sound device every time I want to
  249. set a note?
  250.  
  251. library SoundDLL;
  252.  
  253. uses WinTypes, WinProcs;
  254.  
  255. procedure PlayNote(Note, nLength, Cdots: Integer);export; begin
  256.     OpenSound;
  257.     SetVoiceAccent(1,100,255,S_NORMAL,0);
  258.     SetVoiceQueueSize(1,1000);
  259.     SetVoiceNote(1,Note,nLength,Cdots);
  260.     StartSound;
  261.     WaitSoundState(S_QueueEmpty);
  262.     CloseSound;
  263.     StopSound; end;
  264.  
  265. exports PlayNote index 1;
  266.  
  267. begin end.
  268.  
  269. The declaration in VB (general):
  270.  
  271. Declare Sub PlayNote Lib "e:\tpw\output\soundll.dll" (ByVal note%, ByVal
  272. Length%, ByVal Cdots%)
  273.  
  274. (Mark N.):
  275. The size of the voice queue is one of those numbers that you simply "Pull
  276. out of thin air". It depends on what you're going to do. For example, in
  277. VBTools, we set the queue to 8K because we include several large pieces of
  278. music.
  279.  
  280. OTOH, if you're going to play single notes on an occasional basis, then 1K
  281. should be plenty.
  282.  
  283. It is not necessary to open and close the sound device every time. In fact,
  284. if you close it while there are notes in the queue, they'll be lost!
  285. I suggest that you do what we've done in VBTools:
  286.  
  287. 1. Ope